home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8274 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: ees1a0.engr.ccny.cuny.edu!rpi!not-for-mail
  2. From: overhaul@nmia.com (Daniel N. Sands)
  3. Newsgroups: gnu.g++.help,comp.lang.c++.moderated,comp.lang.c++
  4. Subject: Re: Multiple copies of Virtual Table
  5. Followup-To: gnu.g++.help,comp.lang.c++.moderated,comp.lang.c++
  6. Date: 16 Feb 1996 11:29:32 -0000
  7. Organization: New Mexico Internet Access
  8. Sender: cppmods@netlab.cs.rpi.edu
  9. Approved: devitto@ferndown.ate.slb.com
  10. Message-ID: <4g1pqs$pvl@netlab.cs.rpi.edu>
  11. References: <4fvj0l$ii7@netlab.cs.rpi.edu>
  12. NNTP-Posting-Host: netlab.cs.rpi.edu
  13. X-Original-Date: 16 Feb 1996 06:41:50 GMT
  14.  
  15. Mike ODowd wrote:
  16. #-> I have noticed that the size of my code has been growing
  17. #-> at an alarming rate recently. After some investigation, I
  18. #-> discovered that it is due to multiple copies of virtual tables.
  19. #-> 
  20. #-> It seems that each object file that accesses a class, ends up
  21. #-> with a copy of that class' virtual table. I one case, I counted 
  22. #-> 91 object files that contain a copy of the same virtual table.
  23. #-> 
  24. #-> The virtual tables are taking up something like 25% of my code.
  25. #-> 
  26. #-> Please tell me that there is a way around this, that my code size
  27. #-> is not going to expand exponentially.
  28. #-> 
  29. #-> I am using gcc v2.6.0.
  30.  
  31. I may know what's up:  If you define instances of your class in the 
  32. header file:
  33.  
  34. <foo.h>
  35.  
  36. Myclass Foo1;
  37.  
  38. Every file that includes foo.h will make a copy of Foo1, and a virtual 
  39. table to match.  Make sure all data declared in the header files is 
  40. "extern".  Then define the actual instance in one of your modules.
  41.  
  42. { This isn't a clear example - anyone care to summise the problems of
  43.   inlines/templates and vtbl emmision ?? -mod}
  44.  
  45.       [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
  46.       [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  47.       [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  48.       [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  49.